<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
    <title>Flex Box</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }

        /*设置block的样式*/
        div {
            width: 150px;
            border: solid 1px #f00;
            margin-top: 20px;
        }

        .b4 {
            border:solid 1px #00f;
        }

        /*屏幕大于640px时的布局*/
        @media screen and (min-width: 640px) {
            .b1 {
                height: 120px;
                order: 1;
            }

            .b2 {
                height: 100px;
                order: 2;
            }

            .b3 {
                height: 40px;
                order: 3;
            }

            .b4 {
                height: 200px;
                order: 4;
            }

            /*设置flex布局*/
            body {
                display: flex;
                flex-direction: row;
                flex-wrap: wrap;
                justify-content: space-between;
                align-items: center;
            }
        }

        /*屏幕小于等于640px时的布局*/
        @media screen and (max-width: 640px) {
            .b1 {
                height: 120px;
                order: 1;
            }

            .b2 {
                height: 100px;
                order: 2;
            }

            .b3 {
                height: 40px;
                order: 3;
            }

            .b4 {
                height: 200px;
                order: -1;
            }

            /*设置flex布局*/
            body {
                display: flex;
                flex-direction: row;
                flex-wrap: wrap;
                justify-content: space-between;
                align-items: flex-start;
            }
        }
    </style>
</head>
<body>
    <div class="b1"></div>
    <div class="b2"></div>
    <div class="b3"></div>
    <div class="b4"></div>
</body>
</html>